package com.eshop.gen.rest;

import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.validation.annotation.Validated;
import com.eshop.gen.domain.GenConfig;
import org.springframework.web.bind.annotation.GetMapping;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import com.eshop.gen.service.GenConfigService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({ "/api/genConfig" })
@Api(tags = { "系统：代码生成器配置管理" })
public class GenConfigController
{
    private final GenConfigService genConfigService;
    
    public GenConfigController(final GenConfigService genConfigService) {
        this.genConfigService = genConfigService;
    }
    
    @ApiOperation("查询")
    @GetMapping({ "/{tableName}" })
    public ResponseEntity<Object> get(@PathVariable final String tableName) {
        return (ResponseEntity<Object>)new ResponseEntity((Object)this.genConfigService.find(tableName), HttpStatus.OK);
    }
    
    @ApiOperation("修改")
    @PutMapping
    public ResponseEntity<Object> emailConfig(@Validated @RequestBody final GenConfig genConfig) {
        return (ResponseEntity<Object>)new ResponseEntity((Object)this.genConfigService.update(genConfig.getTableName(), genConfig), HttpStatus.OK);
    }
}
